package org.jgs1904.controller.data;

import org.jgs1904.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author: 默苍璃
 * @date: 2023-05-13 11:31
 * <p>
 * 处理提交数据
 */
@Controller
public class HelloNameController {

    /**
     * 提交的域名称和处理方法的参数名一致
     *
     * @param name
     * @return
     */
    @RequestMapping("/name")
    public String hello(String name, Model model) {
        System.out.println(name);
        return "hello";
    }


    /**
     * 提交的域名称和处理方法的参数名不一致
     * http://localhost:8080/name1?username=999
     *
     * @param name
     * @return
     * @RequestParam("username") : username提交的域的名称 .
     */
    @RequestMapping("/name1")
    public String hello1(@RequestParam("username") String name) {
        System.out.println(name);
        return "hello";
    }


    /**
     * 提交的是一个对象
     * 要求提交的表单域和对象的属性名一致  , 参数使用对象即可
     * http://localhost:8080/user?id=88&name=99&age=666
     *
     * @param user
     * @return
     */
    @RequestMapping("/user")
    public String user(User user) {
        System.out.println(user);
        return "hello";
    }


}
